package org.romzzz.gwtclassifieds.server.data;

import java.io.Serializable;
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import org.romzzz.gwtclassifieds.client.data.ClassifiedBean;

/**
 * This bean represents a simple classified ad that can be stored using JDO.
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Classified implements Serializable {
	
	private static final long serialVersionUID = -621428529595488762L;
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private Boolean offer;
	@Persistent
	private String title;
	@Persistent
	private String body;
	@Persistent
	private Date date;
	@Persistent
	private String category;
	@Persistent
	private String contact;
	@Persistent
	private String password;
	
	public Classified() {}
	
	public Classified(Long id, Boolean sell, String title, String body, Date date, String category, String contact, String password) {
		setId(id);
		setOffer(sell);
		setTitle(title);
		setBody(body);
		setDate(date);
		setCategory(category);
		setContact(contact);
		setPassword(password);
	}
	
	public Classified(Long id, ClassifiedBean gwtBean, String password) {
		this(id, gwtBean.isOffer(), gwtBean.getTitle(), gwtBean.getBody(), gwtBean.getDate(), gwtBean.getCategory().getValue(), gwtBean.getContact(), password);
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public Boolean isOffer() {
		return offer;
	}
	
	public void setOffer(Boolean offer) {
		this.offer = offer;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
    }

	public String getContact() {
		return contact;
	}

	public void setContact(String contact) {
		this.contact = contact;
    }

	public String getPassword() {
		return password;
	}

	public void setPassword(String rndKey) {
		this.password = rndKey;
	}

}
